﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.Page
{
    public partial class CS_DJZT_Query : System.Web.UI.Page
    {
        CS_DJZT_Dao dao = new CS_DJZT_Dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.lbTitle.Text = "查询单据状态";
                BindGridview();
            }
        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            BindGridview();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindGridview();
        }

        private void BindGridview()
        {
            int pageIndex = GridView1.PageIndex;
            List<CS_CPMC> listCPMC = dao.QueryAll();
            List<CS_CPMC_Ex> listEx = new List<CS_CPMC_Ex>();
            CS_CPMC_Ex ce;
            foreach (CS_CPMC c in listCPMC)
            {
                ce = new CS_CPMC_Ex();
                ce.BH = c.BH;
                ce.MC = c.MC;
                ce.CPLXBH = c.CPLXBH;
                ce.CPLXMC = daoCPLX.Query(c.CPLXBH).MC;
                listEx.Add(ce);
            }


            this.GridView1.DataSource = listEx;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((LinkButton)(e.Row.Cells[1].Controls[0])).Attributes.Add("onclick ", "return   confirm( '确定删除？ ') ");
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string bh = GridView1.DataKeys[e.RowIndex].Value.ToString();
            string cplxbh = GridView1.Rows[e.RowIndex].Cells[2].Text;
            int result = dao.Delete(cplxbh, bh);
            if (result == 1)
            {
                lbResult.Text = "删除成功";
                BindGridview();
            }
        }

        protected class CS_CPMC_Ex
        {
            public string BH { get; set; }
            public string CPLXBH { get; set; }
            public string MC { get; set; }
            public string CPLXMC { get; set; }
        }
    }
}